﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using MediaPortal.GUI.Library;

namespace MediaPortal.GUI.iPlayer
{
    public class common_classes
    {
        
        /// <summary>
        /// Open web session and get the image
        /// </summary>
        public string DownloadImage(string url)
        {
            // Log.Info("TVGemist: Trying to get following image: {0}", url.ToString());

            try
            {
                string thumbsDir = MediaPortal.Configuration.Config.GetFolder(MediaPortal.Configuration.Config.Dir.Thumbs);

                WebClient wc = new WebClient();
                string filename = url.Substring(url.LastIndexOf("/") + 1);

                wc.DownloadFile(url, thumbsDir + @"\MPTemp-" + filename);
                while (System.IO.File.Exists(thumbsDir + @"\MPTemp-" + filename) != true)
                    GUIWindowManager.Process();
                return thumbsDir + @"\MPTemp-" + filename;
            }
            catch (Exception e)
            {
                Log.Info(e.Message);
                return string.Empty;
            }
        }
    }
}
